import axios from 'axios';
//全局配置
axios.defaults.baseURL = '';
//axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
//覆盖库的超时默认值
//现在所有请求将在超时前等待2.5秒
axios.defaults.timeout = 2500;
//拦截器处理
//发送前处理
axios.interceptors.request.use(function(config){
    //判断是否有token
    let token=localStorage.getItem('authenticationtoken');
    if(null!=token&&typeof token!='undefined'&&token.trim!=''){
        config.headers.Authorization=token;
    }else{
        console.log('token不存在');
    }
    return config;
},function(error){
    return Promise.reject(error);
});
//添加响应拦截器
axios.interceptors.response.use(function(response){
    console.log("response:"+JSON.stringify(response));    
    return response;
},function(error){
    console.log(error);
    return Promise.reject(error,'服务器响应失败');
});